package com.wenwan.manage.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wenwan.manage.service.GiveGetCommentService;
import com.wenwan.manage.setting.DefaultValue;

import javax.annotation.Resource;

/**
 * 供求文章评论
 * 
 * @author Admin
 *
 */
@Controller
@RequestMapping(value = "/give/get/comment")
public class GiveGetCommentController {

	@Autowired
	private GiveGetCommentService giveGetCommentService;

	/**
	 * 供求文章评论
	 * 
	 * @param content
	 *            评论内容
	 * @param giveGetId
	 *            供求文章ID
	 * @param userId
	 *            用户ID
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/create", method = { RequestMethod.POST })
	public Map<String, Object> create(@RequestParam(required = true) String content,
			@RequestParam(required = true) String giveGetId, @RequestParam(required = true) String userId) {
		return giveGetCommentService.create(content, giveGetId, userId);
	}

	/**
	 * 删除供求文章评论
	 * 
	 * @param id
	 *            供求文章评论ID
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/delete/by/id", method = { RequestMethod.POST })
	public Map<String, Object> deleteById(@RequestParam(required = true) String id) {
		return giveGetCommentService.deleteById(id);
	}

	/**
	 * 更新供求文章评论
	 * 
	 * @param id
	 *            供求文章评论ID
	 * @param content
	 *            评论内容
	 * @param giveGetId
	 *            供求文章ID
	 * @param userId
	 *            评论者ID
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/update", method = { RequestMethod.POST })
	public Map<String, Object> update(@RequestParam(required = true) String id,
			@RequestParam(required = false) String content, @RequestParam(required = false) String giveGetId,
			@RequestParam(required = false) String userId) {
		return giveGetCommentService.update(id, content, giveGetId, userId);
	}

	/**
	 * 查询评论
	 * 
	 * @param currentPage
	 *            当前页
	 * @param pageSize
	 *            每页显示条数
	 * @param giveGetId
	 *            供求文章ID
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/select/all", method = { RequestMethod.GET })
	public Map<String, Object> selectAll(
			@RequestParam(required = false, defaultValue = DefaultValue.CURRENT_PAGE) Integer currentPage,
			@RequestParam(required = false, defaultValue = DefaultValue.PAGE_SIZE) Integer pageSize,
			@RequestParam(required = true) String giveGetId) {
		return giveGetCommentService.selectAll(currentPage, pageSize, giveGetId);
	}

	/**
	 * 查询单个评论
	 * 
	 * @param id
	 *            评论ID
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/select/one/by/id", method = { RequestMethod.GET })
	public Map<String, Object> selectOneById(@RequestParam(required = true) String id) {
		return giveGetCommentService.selectOneById(id);
	}

}
